function [err, EPSCresult]=EPSC_noise()
% Analyze the Mean and Variance of a set of EPSPs
% Derived from EPSP_COV
% Expects data to be a series of EPSCs in a train, 10 msec apart.
% Oleskovich et al., 1999
% Paul B. Manis, Ph.D.
% pmanis@med.unc.edu
% Initial versions: 4/2002, 5/2002.
% 6/2/2002.
% 12/1/02
%
global CONTROL
try
   sf = getmainselection;
   if(sf > 0) 
      pflag = getplotflag;
      QueMessage('EPSC_Noise analysis', 1); % clear the que
      for i = 1:length(sf)
         epsc = CONTROL(sf(i)).EPSC_MeanVar;
         im(i) = epsc.Im(1)/1000;
         var(i) = epsc.Ivar(1)/1000^2;
      end;
      % do the analysis and print the result.
      qcv = 0.32; % quantal variance
      % transform equation to linear form.
      % y = Ax - Bx^2 -> y/x = A - Bx
      y = var./im;
      [B A] = linreg(im, y);
      Qav = A/(1 + qcv^2);
      Nmin = -1/B;
      Pr = -im*(A/B)*(1+qcv^2);
      fprintf('%s     Qav = %8.3f    Nmin  = %8.3f   ', CONTROL(sf(1)).filename, Qav, Nmin);
      fprintf('Pr ');
      fprintf(' %7.3f ', Pr);
      fprintf('\n');
      
      
       QueMessage('EPSC_Noise analysis - finished', 1); % clear the que
     
   end;
catch
   watchoff;
   QueMessage('Error in EPSC_Noise Analysis routine', 1);
end;
